<title>菜单管理</title>
<div class="layui-card">
    <div class="layui-card-body">
        <ul id="tree_sys_menu_select" class="ztree"></ul>
        <input id="select_menu_id" name="select_menu_id" type="hidden"/>
        <input id="select_menu_name" name="select_menu_name" type="hidden"/>
    </div>
</div>
<link rel="stylesheet" href="/static/stv/admin/ztree/css/zTreeStyle/zTreeStyle.css" media="all">
<script src="/static/stv/admin/layui/layuiadmin/layui/layui.js"></script>
<script src="/static/stv/admin/ztree/js/jquery-1.4.4.min.js"></script>
<script src="/static/stv/admin/ztree/js/jquery.ztree.core.js"></script>

<SCRIPT type="text/javascript">


    <!--
    var setting = {
        view: {
            nameIsHTML: true,
            showIcon: false,
            showLine: true,
            txtSelectedEnable: false,
            addDiyDom: addDiyDom
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onExpand: onExpand,
            onCollapse: onCollapse,
            onClick: zTreeOnClick
        }

    };

    var zNodes =<?php print_r($menu_list);?>;
    var  className = "dark";

    //自定义节点
    function addDiyDom(treeId, treeNode) {
        var sObj = $("#" + treeNode.tId + "_span");
        var addStr = "<i class='" + treeNode.icon + "'></i>&nbsp;";
        //在节点前加入 ICON 图标
        sObj.before(addStr);
        var addStr = "&nbsp;(" + treeNode.id + ")";
        sObj.after(addStr);
    }
    function zTreeOnClick(event, treeId, treeNode) {
        console.log(treeNode);
        // parent.submit_form.val({pid:treeNode.id,pname:treeNode.title});
        $("#select_menu_id").val(treeNode.id);
        $("#select_menu_name").val(treeNode.name);

    }

    function addDiyDom(treeId, treeNode) {
        var sObj = $("#" + treeNode.tId + "_span");
        var addStr = "<i class='" + treeNode.icon_css + "'></i>&nbsp;";
        sObj.before(addStr);
    }

    //展开时记录cookie
    function onExpand(event, treeId, treeNode) {
        var cookie_name = "tree_history_" + treeId;
        var cookie = read_cookie(cookie_name);
        var z_tree = new Array();
        if (cookie) {
            z_tree = JSON.parse(cookie);
        }
        if ($.inArray(treeNode.id, z_tree) < 0) {
            z_tree.push(treeNode.id);
        }
        create_cookie(cookie_name, JSON.stringify(z_tree))
    }
    function read_cookie(a) {
        for (var b = a + "=", c = document.cookie.split(";"), d = 0; d < c.length; d++) {
            for (var e = c[d];
                 " " == e.charAt(0);) e = e.substring(1, e.length);
            if (0 == e.indexOf(b)) return e.substring(b.length, e.length)
        }
        return null
    }
    //关闭时记录cookie
    function onCollapse(event, treeId, treeNode) {
        var cookie_name = "tree_history_" + treeId;
        var cookie = read_cookie(cookie_name);
        var z_tree = new Array();
        if (cookie) {
            z_tree = JSON.parse(cookie);
        }
        var index = $.inArray(treeNode.id, z_tree);
        z_tree.splice(index, 1);
        for (var i = 0; i < treeNode.children.length; i++) {
            index = $.inArray(treeNode.children[i].id, z_tree);
            if (index > -1) z_tree.splice(index, 1);
        }
        create_cookie(cookie_name, JSON.stringify(z_tree))
    }

    function getTime() {
        var now= new Date(),
            h=now.getHours(),
            m=now.getMinutes(),
            s=now.getSeconds();
        return (h+":"+m+":"+s);
    }

    $(document).ready(function(){
        $.fn.zTree.init($("#tree_sys_menu_select"), setting, zNodes);
        var treeId = "tree_sys_menu_select";
        var    treeObj = $.fn.zTree.getZTreeObj(treeId);
        treeObj.expandAll(true);
    });
    //-->
</SCRIPT>

